package com.example.demo.controller;

import com.example.demo.pojo.User;
import com.example.demo.service.LoginService;
import com.example.demo.util.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Objects;

@RestController
@Slf4j
public class AffairController {
    @Autowired
    private LoginService loginService;
    @GetMapping("/affair1")
    public String  affair1(HttpSession session){
        User user = (User)session.getAttribute("user");
        if (Objects.nonNull(user)) {

            return "true";
        }
        return "false";
    }

    @GetMapping("/affair2")
    public boolean affair2(HttpSession session){
        User user = RequestContext.getUser(); //通过工具类代替 session.getAttributes("user")
        loginService.doLoginDao(user);
        return true;
    }





}
